<template>
	<view>
		<u-mask :show="loading" :custom-style="{background: 'rgba(0, 0, 0, 0)'}">
			<view class="warp">
				<u-loading mode="flower"></u-loading>
			</view>
		</u-mask>
		<u-navbar title="确认订单" @custom-back="to_detail"></u-navbar>
		<view style="padding: 30rpx;">
			<view class="content">
				<view style="padding: 20rpx;">
					<u-cell-item :arrow="false" :border-bottom="false">
						<template slot="icon">
							<image style="width: 110rpx;height: 110rpx;border-radius: 50%;" :src="teacher_info.image"></image>
						</template>
						<template slot="title">
							<view style="margin-left: 30rpx;">
								<view style="font-size: 30rpx;font-weight:900">{{teacher_info.name}}</view>
								<view style="font-size: 30rpx;">{{product_info.store_name}}</view>
								<view style="font-size: 30rpx;">
									<text style="color: #F0AD4E;">{{product_info.unit_name}}</text>课时
								</view>
							</view>
						</template>
						<template slot="right-icon">
							<view>￥ {{product_info.price}}</view>
						</template>
					</u-cell-item>
				</view>
			</view>
			<view style="height: 50rpx;"></view>
			<view class="content">
				<view style="padding: 20rpx;">
					<u-cell-item :arrow="false" title="课程总额" :value="'￥' + product_info.price"></u-cell-item>
					<u-cell-item :arrow="false" :border-bottom="false" title="需付款">
						<template slot="right-icon">
							<view style="color: #F0AD4E;">￥ {{product_info.price}}</view>
						</template>
					</u-cell-item>
				</view>
			</view>
		</view>
		<uni-goods-nav class="goods-nav" :fill="true" :options="options" :buttonGroup="buttonGroup" @buttonClick="submit"></uni-goods-nav>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex';
	export default {
		computed: mapState(['uerInfo']),
		data() {
			return {
				loading:true,
				product_id: 0,
				product_info:{price:0},
				teacher_info:[],
				buttonGroup: [
					{
						text: '立即支付',
						backgroundColor: '#ffa200',
						color: '#fff'
					}
				],
				options:[]
			}
		},
		onLoad(option) {
			this.product_id = option["pruduct_id"];
			this.init();
		},
		methods: {
			to_detail() {
				uni.navigateBack({
					animationType:'pop-out'
				})
			},
			init() {
				uni.request({
					url: `${this.$serverUrl}/product/detail/${this.product_id}`,
					header: {
						"Content-Type": "application/json"
					},
					data: {
						"uid": this.uerInfo.uid,
					},
					method: "GET",
					success: (e) => {
						this.loading = false;
						if (e.data.status == 200) {
							this.product_info = e.data.data.storeInfo;
							this.teacher_info = e.data.data.system_store;
						} else {
							this.$toast_fail(e.data);
						}
					},
					fail: (e) => {
						this.$toast_fail({msg:"请求失败"});
					}
				});
			},
			submit() {
				uni.requestPayment({
					provider: 'wxpay',
					orderInfo: {
						
					},
					success: function (res) {
						console.log('success:' + JSON.stringify(res));
					},
					fail: function (err) {
						console.log('fail:' + JSON.stringify(err));
					}
				})
			}
		}
	}
</script>

<style>
	.warp {
		display: flex;
		align-items: center;
		justify-content: center;
		height: 100%;
	}
	.content {
		width: 100%;
		padding: 0 0 0 0;
		background-color: #fff;
		box-shadow: 0upx 0upx 25upx rgba(0,0,0,0.1);
		border-radius: 15upx;
	}
	.goods-nav {
		position: fixed;
		bottom: 0;
		width: 100%;
	}
</style>
